Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sheath leaf clauses with SqlQuery-centric logic #3057

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

deusaquilus
Copy link
Collaborator

SheathLeafClauses is buggy and fails for even simple examples like this:

  case class Parent(id: Int, name: String)
  case class Child(parentId: Int, name: String)

  val ids = quote {
    (for {
      p <- query[Parent]
      a <- query[Child].join(a => a.parentId == p.id)
    } yield p.id).distinct
  }

  val parentChildJoined = quote {
    for {
      id <- ids
      p  <- query[Parent].join(p => p.id == id)
      c  <- query[Child].join(c => c.parentId == p.id)
    } yield (p, c)
  }

Throws an error during beta reduction (TODO get the error).

We want to replace the logic with a more practical set of transforms that happen on SqlQuery since that is the place where it should mater that clauses cannot be primitive. The ideal place to do this is between SqlQuery and ExpandNestedQuery because at that time every single SqlQuery that has only one primitive-valued SelectValue (in the FlattenSqlQuery.select) must correspond to a type of situation resembling SELECT primitive FROM (SELECT x.primitive FROM ...) AS primitive. It makes it easier to turn the whole construct into something friendly to SQL like: SELECT primitive.value FROM (SELECT x.primitive AS value FROM ...) AS primitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants